package com.fwixvye.service.impl;

import com.fwixvye.mapper.CharacterMapper;
import com.fwixvye.mapper.RelicsMapper;
import com.fwixvye.mapper.WeaponMapper;
import com.fwixvye.pojo.*;
import com.fwixvye.pojo.Character;
import com.fwixvye.service.CharacterDamageCalculationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class CharacterDamageCalculationServiceImpl implements CharacterDamageCalculationService {

    @Autowired
    CharacterMapper characterMapper;

    @Autowired
    WeaponMapper weaponMapper;

    @Autowired
    RelicsMapper relicsMapper;


    /**
     * 请求数据库查找人物信息，武器信息，圣遗物信息
     */
    @Override
    public Result searchAll(TopBarSumit topBarSumit) {

        Character character = characterMapper.selectAllByName(topBarSumit.getRoleImgUrl());
        Weapon weapon = weaponMapper.selectAllByName(topBarSumit.getWeaponImgUrl());
        Relics relics0 = relicsMapper.selectAllByName(topBarSumit.getReliceImgUrl()[0].replace("生之花", ""));
        Relics relics1 = relicsMapper.selectAllByName(topBarSumit.getReliceImgUrl()[1].replace("生之花", ""));
        Role role = new Role();
        role.name = character.getName();
        role.hp_b = character.getHpB();
        role.atk_b = character.getAtkB() + weapon.getMainEntry();
        role.def_b = character.getDefB();
        role.as_b = character.getBreakthroughBonus();
        role.as_t = character.getBreakthroughBonusType();
        role.ms_b = 240;

        role.holyRelicsTwoPieceSetBonus(relics0);//圣遗物二件套加成
        if (relics0.getName() != relics1.getName()) {//如果是2+2圣遗物
            role.holyRelicsTwoPieceSetBonus(relics1);
        }
        role.weaponAdverbAddition(weapon);//将武器副词条加成加上。
        role.initRefreshTotal();//刷新所有值总量

        ArrayList<Object> list = new ArrayList<>();
        list.add(character);
        list.add(weapon);
        list.add(relics0);
        list.add(relics1);
        list.add(role);

        return Result.success(list);
    }
}
